package com.atguigu.gulimall.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * 网关限流配置
 * @author zxl
 * @date 2020年8月28日10:03:56
 */
@Configuration
public class RequestRateLimiterConfig {

    /**
     * 基于用户参数限流
     * @return
     */
   /* @Bean
    KeyResolver userKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("fwcloud"));
    }*/

    /**
     * 基于ip限流
     * @return
     */
   @Bean
    KeyResolver ipKeyResolver() {
       return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
   }

    /**
     * 基于请求路径
     * @return
     */
   /* @Bean
    KeyResolver apiKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getPath().value());
    }*/
}
